import 'package:flutter/material.dart';
import 'help_screen.dart';
import 'about_screen.dart';

class OthersScreen extends StatefulWidget {
  const OthersScreen({Key? key}) : super(key: key);

  @override
  State<OthersScreen> createState() => _OthersScreenState();
}

class _OthersScreenState extends State<OthersScreen> {
  final List<Map<String, dynamic>> _menuItems = [
    {
      'title': 'ھەققىمىزدە',
      'icon': Icons.info_outline,
      'onTap': 'about',
      'description': 'شىركەت ۋە پروگرامما ھەققىدە ئۇچۇرلار',
    },
    {
      'title': 'ياردەم',
      'icon': Icons.help_outline,
      'onTap': 'help',
      'description': 'داۋاملىق سورالغان سوئاللار ۋە ياردەم مەزمۇنلىرى',
    },
    {
      'title': 'تەڭشەكلەر',
      'icon': Icons.settings_outlined,
      'onTap': 'settings',
      'description': 'پروگرامما تەڭشەكلىرى ۋە ئۇلانما تالاش',
    },
    {
      'title': 'تور بەت',
      'icon': Icons.language_outlined,
      'onTap': 'website',
      'description': 'رەسمىي تور بېتىمىزنى زىيارەت قىلىش',
    },
    {
      'title': 'باھالاش',
      'icon': Icons.star_outline,
      'onTap': 'rate',
      'description': 'پروگراممىنى باھالاش ۋە تەكلىپ بېرىش',
    },
    {
      'title': 'ھەمبەھىرلەش',
      'icon': Icons.share_outlined,
      'onTap': 'share',
      'description': 'پروگراممىنى دوستلىرىڭىزغا تونۇشتۇرۇش',
    },
  ];

  void _handleMenuItemTap(String action) {
    switch (action) {
      case 'about':
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => const AboutScreen(),
          ),
        );
        break;
      case 'help':
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => const HelpScreen(),
          ),
        );
        break;
      case 'settings':
        // Navigator.of(context).pop();
        // Navigator.push(
        //   context,
        //   MaterialPageRoute(
        //     builder: (context) => const SettingsScreen(),
        //   ),
        // );
        _showNotImplementedDialog('تەڭشەكلەر');
        break;
      case 'website':
        _showNotImplementedDialog('تور بەت');
        break;
      case 'rate':
        _showNotImplementedDialog('باھالاش');
        break;
      case 'share':
        _showNotImplementedDialog('ھەمبەھىرلەش');
        break;
    }
  }

  void _showNotImplementedDialog(String feature) {
    showDialog(
      context: context,
      builder: (context) => AlertDialog(
        title: Text('$feature ھازىرچە تاماملانمىدى'),
        content: const Text('بۇ فۇنكسىيە كېيىنكى نەشرىدە قوشۇلىدۇ.'),
        actions: [
          TextButton(
            onPressed: () => Navigator.pop(context),
            child: const Text('تامام'),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('باشقىلار'),
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              _buildInfoCard(),
              const SizedBox(height: 24),
              const Text(
                'مۇناسىۋەتلىك مەزمۇنلار',
                style: TextStyle(
                  fontSize: 18,
                  fontWeight: FontWeight.bold,
                ),
              ),
              const SizedBox(height: 16),
              _buildMenuGrid(),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildInfoCard() {
    return Container(
      width: double.infinity,
      decoration: BoxDecoration(
        gradient: const LinearGradient(
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          colors: [Colors.blue, Colors.lightBlueAccent],
        ),
        borderRadius: BorderRadius.circular(16),
      ),
      child: Padding(
        padding: const EdgeInsets.all(20.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Container(
                  padding: const EdgeInsets.all(12),
                  decoration: BoxDecoration(
                    color: Colors.white.withOpacity(0.2),
                    shape: BoxShape.circle,
                  ),
                  child: const Icon(
                    Icons.storefront,
                    color: Colors.white,
                    size: 32,
                  ),
                ),
                const SizedBox(width: 16),
                const Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        'تىجارەت',
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 24,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      Text(
                        'نەشرى 1.0.0',
                        style: TextStyle(
                          color: Colors.white70,
                          fontSize: 16,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
            const SizedBox(height: 24),
            const Text(
              'سىزنىڭ سودىڭىز ئۈچۈن ئەڭ ياخشى ئاساسنى قۇرىمىز',
              style: TextStyle(
                color: Colors.white,
                fontSize: 16,
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildMenuGrid() {
    return GridView.builder(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        childAspectRatio: 1.1,
        crossAxisSpacing: 12,
        mainAxisSpacing: 12,
      ),
      itemCount: _menuItems.length,
      itemBuilder: (context, index) {
        final item = _menuItems[index];
        return _buildMenuItem(
          title: item['title'],
          icon: item['icon'],
          description: item['description'],
          onTap: () => _handleMenuItemTap(item['onTap']),
        );
      },
    );
  }

  Widget _buildMenuItem({
    required String title,
    required IconData icon,
    required String description,
    required VoidCallback onTap,
  }) {
    return InkWell(
      onTap: onTap,
      borderRadius: BorderRadius.circular(16),
      child: Container(
        padding: const EdgeInsets.all(16),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(16),
          boxShadow: [
            BoxShadow(
              color: Colors.grey.withOpacity(0.1),
              blurRadius: 10,
              spreadRadius: 0.5,
            ),
          ],
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              padding: const EdgeInsets.all(10),
              decoration: BoxDecoration(
                color: Colors.blue.withOpacity(0.1),
                borderRadius: BorderRadius.circular(12),
              ),
              child: Icon(
                icon,
                color: Colors.blue,
                size: 26,
              ),
            ),
            const SizedBox(height: 16),
            Text(
              title,
              style: const TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: 16,
              ),
            ),
            const SizedBox(height: 8),
            Text(
              description,
              style: TextStyle(
                color: Colors.grey.shade600,
                fontSize: 12,
              ),
              maxLines: 2,
              overflow: TextOverflow.ellipsis,
            ),
          ],
        ),
      ),
    );
  }
}
